char * str_utf8_to_cp1252( const char * str );
char * str_utf8_to_ascii( const char * str );
+/* this lives in gpx.c */
+time_t xml_parse_time( char *cdatastr );
+
+xml_tag *xml_findfirst( xml_tag *root, char *tagname );
+xml_tag *xml_findnext( xml_tag *root, xml_tag *cur, char *tagname );
+char *xml_attribute( xml_tag *tag, char *attrname );
+
char * rot13( const char *str );
/*
return "Unknown";
}
-static
time_t
xml_parse_time( char *cdatastr )
{
static char *stylesheet = NULL;
static char *encrypt = NULL;
+static char *includelogs = NULL;
#define MYNAME "HTML"
"Path to HTML style sheet", ARGTYPE_STRING },
{ "encrypt", &encrypt,
"Encrypt hints using ROT13", ARGTYPE_BOOL },
+ { "logs", &includelogs,
+ "Include groundspeak logs if present", ARGTYPE_BOOL },
{0, 0, 0, 0}
};
fprintf(file_out, "<a name=\"%s\"></a><table width=\"100%%\"><tr><td>\n", wpt->shortname);
fprintf(file_out, "<h3 class=\"waypoint\">%s - %c%d°%06.3f %c%d°%06.3f (%ld%c %6.0f %7.0f)",
(global_opts.synthesize_shortnames) ? mkshort(mkshort_handle, wpt->description) : wpt->shortname,
- wpt->latitude < 0 ? 'S' : 'N', abs(latint), 60.0 * (fabs(wpt->latitude) - latint),
- wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint),
+ wpt->latitude < 0 ? 'S' : 'N', latint, 60.0 * (fabs(wpt->latitude) - latint),
+ wpt->longitude < 0 ? 'W' : 'E', lonint, 60.0 * (fabs(wpt->longitude) - lonint),
utmz, utmzc, utme, utmn);
if (wpt->altitude != unknown_alt)
fprintf (file_out, " alt: %1.1f", wpt->altitude);
else if (!wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
fprintf (file_out, "<p class=\"notes\">%s</p>\n", wpt->notes);
}
+ if ( includelogs && wpt->gpx_extras ) {
+ xml_tag *root = wpt->gpx_extras;
+ xml_tag *curlog = NULL;
+ xml_tag *logpart = NULL;
+ curlog = xml_findfirst( root, "groundspeak:log" );
+ while ( curlog ) {
+ fprintf( file_out, "<p class=\"log\">\n" );
+ time_t logtime = 0;
+ struct tm *logtm = NULL;
+
+ logpart = xml_findfirst( curlog, "groundspeak:type" );
+ if ( logpart ) {
+ fprintf( file_out, "<span class=\"logtype\">%s</span> by ", logpart->cdata );
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:finder" );
+ if ( logpart ) {
+ char *f = html_entitize( logpart->cdata );
+ fprintf( file_out, "<span class=\"logfinder\">%s</span> on ", f );
+ xfree( f );
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:date" );
+ if ( logpart ) {
+ logtime = xml_parse_time( logpart->cdata );
+ logtm = localtime( &logtime );
+ if ( logtm ) {
+ fprintf( file_out,
+ "<span class=\"logdate\">%2.2d/%2.2d/%4.4d</span><br>\n",
+ logtm->tm_mon+1,
+ logtm->tm_mday,
+ logtm->tm_year+1900
+ );
+ }
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:log_wpt" );
+ if ( logpart ) {
+ char *coordstr = NULL;
+ float lat = 0;
+ int latdeg = 0;
+ float lon = 0;
+ int londeg = 0;
+ coordstr = xml_attribute( logpart, "lat" );
+ if ( coordstr ) {
+ lat = atof( coordstr );
+ }
+ coordstr = xml_attribute( logpart, "lon" );
+ if ( coordstr ) {
+ lon = atof( coordstr );
+ }
+ latdeg = abs(lat);
+ londeg = abs(lon);
+
+ fprintf( file_out,
+ "<span class=\"logcoords\">%c %d° %.3f' %c %d° %.3f'</span><br>\n",
+
+ lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg),
+ lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg)
+ );
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:text" );
+ if ( logpart ) {
+ char *encstr = NULL;
+ char *s = NULL;
+ char *t = NULL;
+ int encoded = 0;
+ encstr = xml_attribute( logpart, "encoded" );
+ encoded = (encstr[0] != 'F');
+
+ if ( encrypt && encoded ) {
+ s = rot13( logpart->cdata );
+ }
+ else {
+ s = xstrdup( logpart->cdata );
+ }
+
+ t = html_entitize( s );
+ fprintf( file_out, "%s", t );
+ xfree( t );
+ xfree( s );
+ }
+
+ fprintf( file_out, "</p>\n" );
+ curlog = xml_findnext( root, curlog, "groundspeak:log" );
+ }
+ }
fprintf(file_out, "</td></tr></table>\n");
}
static char *suppresssep = NULL;
static char *dbname = NULL;
+static char *includelogs = NULL;
static int ct = 1;
static int offset = 0;
"Suppress separator lines between waypoints", ARGTYPE_BOOL },
{"dbname", &dbname, "Database name", ARGTYPE_STRING },
{"encrypt", &encrypt, "Encrypt hints with ROT13", ARGTYPE_BOOL },
+ { "logs", &includelogs,
+ "Include groundspeak logs if present", ARGTYPE_BOOL },
{0, 0, 0, 0}
};
else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
docprintf (10+strlen(wpt->notes), "%s\n", wpt->notes);
}
+
+ if ( includelogs && wpt->gpx_extras ) {
+ xml_tag *root = wpt->gpx_extras;
+ xml_tag *curlog = NULL;
+ xml_tag *logpart = NULL;
+ curlog = xml_findfirst( root, "groundspeak:log" );
+ while ( curlog ) {
+ docprintf( 10, "\n" );
+ time_t logtime = 0;
+ struct tm *logtm = NULL;
+
+ logpart = xml_findfirst( curlog, "groundspeak:type" );
+ if ( logpart ) {
+ docprintf( 10+strlen(logpart->cdata), "%s by ", logpart->cdata );
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:finder" );
+ if ( logpart ) {
+ docprintf( 10+strlen(logpart->cdata), "%s on ", logpart->cdata );
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:date" );
+ if ( logpart ) {
+ logtime = xml_parse_time( logpart->cdata );
+ logtm = localtime( &logtime );
+ if ( logtm ) {
+ docprintf( 15,
+ "%2.2d/%2.2d/%4.4d\n",
+ logtm->tm_mon+1,
+ logtm->tm_mday,
+ logtm->tm_year+1900
+ );
+ }
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:log_wpt" );
+ if ( logpart ) {
+ char *coordstr = NULL;
+ float lat = 0;
+ int latdeg = 0;
+ float lon = 0;
+ int londeg = 0;
+ coordstr = xml_attribute( logpart, "lat" );
+ if ( coordstr ) {
+ lat = atof( coordstr );
+ }
+ coordstr = xml_attribute( logpart, "lon" );
+ if ( coordstr ) {
+ lon = atof( coordstr );
+ }
+ latdeg = abs(lat);
+ londeg = abs(lon);
+
+ docprintf( 30,
+ "%c %d\xb0 %.3f' %c %d\xb0 %.3f'\n",
+
+ lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg),
+ lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg)
+ );
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:text" );
+ if ( logpart ) {
+ char *encstr = NULL;
+ char *s = NULL;
+ int encoded = 0;
+ encstr = xml_attribute( logpart, "encoded" );
+ encoded = (encstr[0] != 'F');
+
+ if ( encrypt && encoded ) {
+ s = rot13( logpart->cdata );
+ }
+ else {
+ s = xstrdup( logpart->cdata );
+ }
+
+ docprintf( 5+strlen(s), "%s", s );
+ xfree( s );
+ }
+
+ docprintf( 10, "\n" );
+ curlog = xml_findnext( root, curlog, "groundspeak:log" );
+ }
+ }
if (! suppresssep)
docprintf(50, "---------------------------\n");
else
static char *suppresssep = NULL;
static char *encrypt = NULL;
+static char *includelogs = NULL;
#define MYNAME "TEXT"
"Suppress separator lines between waypoints", ARGTYPE_BOOL },
{ "encrypt", &encrypt,
"Encrypt hints using ROT13", ARGTYPE_BOOL },
+ { "logs", &includelogs,
+ "Include groundspeak logs if present", ARGTYPE_BOOL },
{0, 0, 0, 0}
};
else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
fprintf (file_out, "%s\n", wpt->notes);
}
+
+ if ( includelogs && wpt->gpx_extras ) {
+ xml_tag *root = wpt->gpx_extras;
+ xml_tag *curlog = NULL;
+ xml_tag *logpart = NULL;
+ curlog = xml_findfirst( root, "groundspeak:log" );
+ while ( curlog ) {
+ fprintf( file_out, "\n" );
+ time_t logtime = 0;
+ struct tm *logtm = NULL;
+
+ logpart = xml_findfirst( curlog, "groundspeak:type" );
+ if ( logpart ) {
+ fprintf( file_out, "%s by ", logpart->cdata );
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:finder" );
+ if ( logpart ) {
+ fprintf( file_out, "%s on ", logpart->cdata );
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:date" );
+ if ( logpart ) {
+ logtime = xml_parse_time( logpart->cdata );
+ logtm = localtime( &logtime );
+ if ( logtm ) {
+ fprintf( file_out,
+ "%2.2d/%2.2d/%4.4d\n",
+ logtm->tm_mon+1,
+ logtm->tm_mday,
+ logtm->tm_year+1900
+ );
+ }
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:log_wpt" );
+ if ( logpart ) {
+ char *coordstr = NULL;
+ float lat = 0;
+ int latdeg = 0;
+ float lon = 0;
+ int londeg = 0;
+ coordstr = xml_attribute( logpart, "lat" );
+ if ( coordstr ) {
+ lat = atof( coordstr );
+ }
+ coordstr = xml_attribute( logpart, "lon" );
+ if ( coordstr ) {
+ lon = atof( coordstr );
+ }
+ latdeg = abs(lat);
+ londeg = abs(lon);
+
+ fprintf( file_out,
+ "%c %d %.3f' %c %d %.3f'\n",
+
+ lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg),
+ lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg)
+ );
+ }
+
+ logpart = xml_findfirst( curlog, "groundspeak:text" );
+ if ( logpart ) {
+ char *encstr = NULL;
+ char *s = NULL;
+ int encoded = 0;
+ encstr = xml_attribute( logpart, "encoded" );
+ encoded = (encstr[0] != 'F');
+
+ if ( encrypt && encoded ) {
+ s = rot13( logpart->cdata );
+ }
+ else {
+ s = xstrdup( logpart->cdata );
+ }
+
+ fprintf( file_out, "%s", s );
+ xfree( s );
+ }
+
+ fprintf( file_out, "\n" );
+ curlog = xml_findnext( root, curlog, "groundspeak:log" );
+ }
+ }
if (! suppresssep)
fprintf(file_out, "-----------------------------------------------------------------------------\n");
else
{
return entitize(str, 1);
}
+
+/*
+ * xml_tag utilities
+ */
+
+xml_tag *xml_next( xml_tag *root, xml_tag *cur )
+{
+ if ( cur->child ) {
+ cur = cur->child;
+ }
+ else if ( cur->sibling ) {
+ cur = cur->sibling;
+ }
+ else {
+ cur = cur->parent;
+ if ( cur == root ) {
+ cur = NULL;
+ }
+ if ( cur ) {
+ cur = cur->sibling;
+ }
+ }
+ return cur;
+}
+
+xml_tag *xml_findnext( xml_tag *root, xml_tag *cur, char *tagname )
+{
+ xml_tag *result = cur;
+ do {
+ result = xml_next( root, result );
+ } while ( result && case_ignore_strcmp( result->tagname, tagname ));
+ return result;
+}
+
+xml_tag *xml_findfirst( xml_tag *root, char *tagname )
+{
+ return xml_findnext( root, root, tagname );
+}
+
+char *xml_attribute( xml_tag *tag, char *attrname )
+{
+ char *result = NULL;
+ if ( tag->attributes ) {
+ char **attr = tag->attributes;
+ while ( attr && *attr ) {
+ if ( 0 == case_ignore_strcmp( *attr, attrname )) {
+ result = attr[1];
+ break;
+ }
+ attr+=2;
+ }
+ }
+ return result;
+}